package com.chen.nongansampling.presenter;

import android.content.Context;

import com.chen.nongansampling.bean.getOperatingByPkId;
import com.chen.nongansampling.bean.getOperingByPkIdRequest;
import com.chen.nongansampling.manager.DataManager;
import com.chen.nongansampling.model.CallbackData;
import com.chen.nongansampling.presenterView.getoperatingbypkid;

import java.util.List;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class getOperatingByPkIdPresenter extends BasePresenter{
    private Context mContext;
    private CallbackData<List<getOperatingByPkId>> callbackData;

    private getoperatingbypkid baseView;
    public getOperatingByPkIdPresenter(Context context){
        this.mContext = context;
    }
    @Override
    public void BindPresentView(Object presentView) {
        baseView = (getoperatingbypkid) presentView;
    }

    public  void getOperatingByPkIdPresenterResponseInfo(getOperingByPkIdRequest getOperingByPkIdRequest) {

        DataManager.getInstance(mContext).getOperatingByPkId(getOperingByPkIdRequest)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new Observer<CallbackData<List<getOperatingByPkId>>>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(CallbackData<List<getOperatingByPkId>> accountCallbackData) {

                        callbackData = accountCallbackData;
                    }



                    @Override
                    public void onError(Throwable e) {
                        baseView.onError(e.toString());
                    }

                    @Override
                    public void onComplete() {
                        if (callbackData != null) {
                            baseView.getOperatorList(callbackData);

                        }
                        //SamplePresenter.super.compositeDisposable.dispose();
                    }
                });
    }
}
